home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / glibc108.zip / glibc108 / setjmp / setjmp.h < prev    next >
C/C++ Source or Header  |  1993-07-25  |  4KB  |  132 lines

  1. /* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. /*
  20.  *    ANSI Standard: 4.6 NON-LOCAL JUMPS <setjmp.h>
  21.  */
  22.  
  23. #ifndef    _SETJMP_H
  24.  
  25. #define    _SETJMP_H    1
  26. #include <features.h>
  27.  
  28. __BEGIN_DECLS
  29.  
  30. /* Get the machine-dependent definition of `__jmp_buf'.  */
  31. #include <jmp_buf.h>
  32.  
  33.  
  34. #ifdef    __USE_POSIX
  35. #define    __need_sigset_t
  36. #include <signal.h>
  37.  
  38. /* Calling environment, plus possibly a saved signal mask.  */
  39. typedef struct
  40.   {
  41.     __jmp_buf __jmpbuf;        /* Calling environment.  */
  42.     int __mask_was_saved;    /* Saved the signal mask?  */
  43.     sigset_t __saved_mask;    /* Saved signal mask.  */
  44.   } sigjmp_buf[1];
  45.  
  46. /* Store the calling environment in ENV, also saving the
  47.    signal mask if SAVEMASK is nonzero.  Return 0.  */
  48. extern void __sigjmp_save __P ((sigjmp_buf __env, int __savemask));
  49. #ifdef __GNUC__
  50. #define    sigsetjmp(env, savemask) \
  51.   ({ __typeof ((*((sigjmp_buf *) 0))[0]) *__e = (env);                  \
  52.      __sigjmp_save (__e, (savemask));                          \
  53.      __setjmp (__e[0].__jmpbuf); })
  54. #else
  55. /* Not strictly POSIX-compliant, because it evaluates ENV more than once.  */
  56. #define    sigsetjmp(env, savemask) \
  57.   (__sigjmp_save ((env), (savemask)), __setjmp ((env)[0].__jmpbuf))
  58. #endif
  59.  
  60.  
  61. /* Jump to the environment saved in ENV, making the
  62.    sigsetjmp call there return VAL, or 1 if VAL is 0.
  63.    Restore the signal mask if that sigsetjmp call saved it.  */
  64. extern __NORETURN void siglongjmp __P ((__const sigjmp_buf __env, int __val));
  65. #endif /* Use POSIX.  */
  66.  
  67.  
  68. #ifdef    __FAVOR_BSD
  69.  
  70. /* BSD defines `setjmp' and `longjmp' to save and restore the set of
  71.    blocked signals.  For this, `jmp_buf' must be what POSIX calls
  72.    `sigjmp_buf', which includes that information.  */
  73. typedef sigjmp_buf jmp_buf;
  74.  
  75. #else /* Don't favor BSD.  */
  76.  
  77. /* A `jmp_buf' really is a `jmp_buf'.  Oh boy.  */
  78. typedef __jmp_buf jmp_buf;
  79.  
  80. #endif /* Favor BSD.  */
  81.  
  82.  
  83. /* Jump to the environment saved in ENV, making the
  84.    setjmp call there return VAL, or 1 if VAL is 0.  */
  85. extern __NORETURN void __longjmp __P ((__const __jmp_buf __env, int __val));
  86. extern __NORETURN void longjmp __P ((__const jmp_buf __env, int __val));
  87.  
  88. #ifdef    __OPTIMIZE__
  89. #define    longjmp(env, val)    __longjmp ((env), (val))
  90. #endif /* Optimizing.  */
  91.  
  92. /* Set ENV to the current position and return 0.  */
  93. extern int __setjmp __P ((__jmp_buf __env));
  94. /* The ANSI C standard says `setjmp' is a macro.  */
  95. #define    setjmp(env)    __setjmp (env)
  96.  
  97.  
  98. #ifdef    __USE_BSD
  99. extern __NORETURN void _longjmp __P ((__const jmp_buf __env, int __val));
  100. #endif /* Use BSD.  */
  101.  
  102. #ifdef    __FAVOR_BSD
  103.  
  104. /* We are in the mode in which `setjmp' and `longjmp' save and restore
  105.    the signal mask, and `jmp_buf' is `sigjmp_buf'.  */
  106.  
  107. #undef    setjmp
  108. #undef    longjmp
  109.  
  110. #define    setjmp(env)        sigsetjmp ((env), 1)
  111.  
  112. #ifdef    __OPTIMIZE__
  113. #define    longjmp(env, val)    siglongjmp ((env), (val))
  114. #endif /* Optimizing.  */
  115.  
  116. #define    _setjmp(env)        sigsetjmp ((env), 0)
  117.  
  118. #else    /* Don't favor BSD.  */
  119.  
  120. /* `setjmp' and `_setjmp' are the same.  */
  121. #define    _setjmp(env)        setjmp (env)
  122.  
  123. /* `longjmp' and `_longjmp' are the same.  */
  124. #define    _longjmp(env, val)    longjmp ((env), (val))
  125.  
  126. #endif /* Favor BSD.  */
  127.  
  128.  
  129. __END_DECLS
  130.  
  131. #endif /* setjmp.h  */
  132.